package com.haier.tv.mic.detect.util;

import android.annotation.SuppressLint;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * author: Max haier
 * email: shangbaorun@haier.com
 * data: 2022/2/19 14:26
 * version: 1.0
 * desc:
 */

public class Utils {
    public static final String CHANNEL_ONE_KEY = "mic_ch0_db";
    public static final String CHANNEL_TWO_KEY = "mic_ch1_db";
    public static final String CHANNEL_THREE_KEY = "mic_ch2_db";
    public static final String CHANNEL_FOUR_KEY = "mic_ch3_db";

    public static String getProperty(String key, String defaultValue) {
        String value = defaultValue;
        try {
            @SuppressLint("PrivateApi") Class<?> c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class, String.class);
            value = (String) (get.invoke(c, key, defaultValue));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return value;
        }
    }

    public static String setProperty(String key, String defaultValue) {
        String value = defaultValue;
        try {
            Class<?> c = Class.forName("android.os.SystemProperties");
            Method set = c.getDeclaredMethod("set", String.class, String.class);
            value = (String) (set.invoke(c, key, defaultValue));
        } catch(InvocationTargetException e) {
            Throwable t = e.getCause();
            t.printStackTrace();
            //throw new ObjectFactoryException(t);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return value;
        }
    }
}
